document.addEventListener('DOMContentLoaded', function() {
	setTimeout(function () {
		if (window.templateId) {
			function clickEvent (statisticBtn, userId) {
				statisticBtn.addEventListener('click', () => {
					// 请求个人数据，打开个人页面
					var url = '/seeyon/relocationDataControl.do?method=showPersonRelocation&user_id=' + userId;
					var screenWidth = screen.width;
					var screenHeight = screen.height;
					var windowFeatures = "location=no,menubar=no,status=no,toolbar=no,resizable=yes,width=" + screenWidth + ",height=" + screenHeight;
					var newWindow = window.open(url, '_blank', windowFeatures);
					if (newWindow) {
						newWindow.moveTo(0, 0);
					}
				});
			}
			// 发送请求判断是否需要显示"Mobilization Record出勤记录按钮"
			$.get('/seeyon/relocationDataControl.do?method=checkRelocation', {
                templateId: window.templateId,
			    affairId: window.affairId
			})
			.done(function(res) {
                var linkElement = document.createElement("link");
				linkElement.href = "/seeyon/apps_res/collaboration/css/ebs.css"; // CSS 文件的路径
				linkElement.type = "text/css";
				linkElement.rel = "stylesheet";
				document.head.appendChild(linkElement);
                if (res.data) {
                    var iconStr = '<span class="hand left" style="font-size:12px;border-radius:20px;padding: 0 16px;margin-right:10px;position: relative;top: -2px;text-align:center;border: 1px solid;color: rgba(62, 160, 254, 1);" id="statisticBtn" onmouseenter="null" onmouseleave="null" onmouseover="null" onmouseout="null"><span class="menu_span" title="Mobilization Record">Mobilization Record</span></span>';
                    var communicationBtn = document.querySelector('#communicationBtns');
                    if (communicationBtn) {
                        var container = communicationBtn;
                        var parser = new DOMParser();
                        var doc = parser.parseFromString(iconStr, 'text/html');
                        var parsedElement = doc.body.firstChild;
                        document.body.appendChild(parsedElement);
                        var statisticBtn = document.getElementById('statisticBtn');
                        container.parentElement.insertBefore(statisticBtn, container);
                        clickEvent(statisticBtn, res.userId);
                    }
                }
			})
		}
	}, 500);
})